<?php ob_start();?>
<?php 
	$root = $_SERVER['DOCUMENT_ROOT'];
//  	include($root.'/standart/head.php');
 	include($root.'/standart/dateHeader.php');
 	include($root.'/standart/dbconnect.php');
 	$db = connect();
 	
 	$tableResult[] = array();
 	$result[] = array();
 	
 	session_start();
if(isset($_SESSION['id'])){	
	$userID = $_SESSION['id'];
		
		$stmt = "
				SELECT o.ID as SiparisNo, m.Product_Name as UrunAdi, i.Price as Fiyat, i.Quantity as Adet, o.Order_Date as SiparisTarihi, o.Total_Amount as Toplam, a.Address_Definition as Address
				FROM ORDER_ITEMS i, ORDERS o, MENU m, ADDRESS a
				where
				o.id = i.order_id
				and
				i.Menu_Id = m.id
				and
				o.Shipping_Address = ".$userID." 
				and
				o.User_id = 1
				order by o.ORDER_DATE desc
				";
		$res = $db->query ( $stmt ) or die ( $stmt . "<br/><br/>" . mysql_error () );
		while($row = $res->fetch_assoc()){
			$result[] = array(
					'SiparisNo' => $row ['SiparisNo'],
					'UrunAdi' => $row ['UrunAdi'],
					'Adet' =>  $row ['Adet'],
					'SiparisTarihi' => date("d/m/Y",strtotime($row ['SiparisTarihi'])),
					'SiparisSaati' => date("H:i",strtotime($row ['SiparisTarihi'])),
					'Toplam' => $row ['Toplam'],
					'Address' => $row ['Address'],
			);
			array_push($tableResult, $result);
// 			return  $result;
		}
	
	
/*	
	//JSON data'nin islenmesi
	class Order {
		public $menuId = "";
		public $orderId  = "";
		public $price = "";
		public $quantity = "";
		public $itemNote = "";
	}
	
	$orderList = array();
	foreach ($resultJS as $key => $item) {
		$order = new Order();
		$order->menuId = $item['menuId'];
		$order->orderId = $lastOrderId;
		$order->price = $item['price'];
		$order->quantity = $item['quantity'];
// 		print_r($order);
		array_push($orderList, $order);
	}
	
	foreach ($orderList as $item) {
		$menuId = $item->menuId;
		$price = $item->price;
		$quantity = $item->quantity;
		
	}
	*/
	
	echo "<br />";
	echo  "<pre>";
// 	echo $tableResult;
	print_r($tableResult);
	echo "</pre>";
	echo "<br />";
	/*
	echo  "<pre>";
	    print_r($_POST);
	echo "</pre>"; 
	echo "<br />";
	echo  "<pre>";
	print_r($addressId);
	print_r($orderDate);
	print_r($totalAmount);
	echo "</pre>";
	echo "<br />";
	echo  "<pre>";
	print_r($resultFD);
	echo "</pre>";
	echo "<br />";
	echo  "<pre>";
	print_r($lastOrderId);
	echo "</pre>";
	*/
	
}
?>
<?php ob_flush(); ?>